<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="访问时长" prop="timeLong">
        <el-input
          v-model="queryParams.timeLong"
          placeholder="请输入访问时长"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="applogList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="appId" align="center" prop="appId" />
      <el-table-column label="app名称" align="center" prop="visitName" />
      <el-table-column label="访问时长" align="center" prop="timeLong" />
      <el-table-column label="调用次数" align="center" prop="count" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['log:applog:query']"
          >详细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!--详细 -->
    <el-dialog title="APP日志详细" :visible.sync="open"   append-to-body>
    <el-table :data="appdetails">
      <el-table-column label="app名称" align="center" prop="visitName" />
      <el-table-column label="访问地址" align="center" prop="visitUrl" />
      <el-table-column label="调用次数" align="center" prop="invokeCount" />
      <el-table-column label="访问时间" align="center" prop="updateTime">
      </el-table-column>
    </el-table>
      <pagination
        v-show="detailtotal>0"
        :total="detailtotal"
        :page.sync="detailParams.pageNum"
        :limit.sync="detailParams.pageSize"
        @pagination="handleDetails"
      />
    </el-dialog>
  </div>
</template>

<script>
import { listApplog, detailsApplog } from "@/api/log/applog";

export default {
  name: "Applog",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedVisitLogInfo: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      detailtotal:0,
      //  日志表格数据
      applogList: [],
      // 日志详细信息
      appdetails:[],
      //  表格数据
      visitLogInfoList: [],
      appId:null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        appId: null,
        startTime: null,
        leaveTime: null,
        timeLong: null,
        tokenKey: null
      },
      detailParams:{
        pageNum: 1,
        pageSize: 10,
        appId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        appId: [
          { required: true, message: "用户的token值不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询 日志列表 */
    getList() {
      this.loading = true;
      listApplog(this.queryParams).then(response => {
        this.applogList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        timeId: null,
        appId: null,
        startTime: null,
        leaveTime: null,
        timeLong: null,
        tokenKey: null
      };
      this.visitLogInfoList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.timeId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 详细按钮操作 */
    handleView(row) {
      this.open = true;
      this.detailParams.appId =row.appId;
      this.appId = row.appId;
      detailsApplog(this.detailParams).then(response => {
        this.appdetails = response.rows;
        this.detailtotal = response.total;
      });
    },
    handleDetails() {
      this.open = true;
      this.detailParams.appId =this.appId;
      detailsApplog(this.detailParams).then(response => {
        this.appdetails = response.rows;
        this.detailtotal = response.total;
      });
    }

  }
};
</script>
